#include <iostream>
#include <vector>
using namespace std;

void dump(vector<int>& ret) {
    for (auto v:ret) {
        cout << v << "\t";
    }
    cout << endl;

}
class Solution {
public:
    vector<int> grayCode(int n) {

        vector<int> ret;
        ret.push_back(0);

        for (int i=0; i<n; i++) {
            vector<int> tmp;
            for (int j=0; j<ret.size(); j++) {
                int v1, v2;
                int val = ret[j];
                if (j%2 == 0) {
                    v1 = val << 1;
                    v2 = val << 1 | 0x01;
                } else {
                    v1 = val << 1 | 0x01;
                    v2 = val << 1;
                }
                tmp.push_back(v1);
                tmp.push_back(v2);
            }
            ret = tmp;
        }

        return ret;
    }
};

int main() {

    Solution s;
    vector<int> ret = s.grayCode(2);
    for (auto v:ret) {
        cout << v << "\t";
    }
    cout << endl;
}
